<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ include file="/common/common.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<c:set var="md" value="on"/>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link rel="stylesheet" type="text/css" href="${base}/css/orderinput.css" />
		<title>${siteName}</title>
		<%@ include file="/common/commonstyle.jsp" %>
		<script type="text/javascript">
			function toPersionOrderInfo() {
				var shopCarSize = $("#shopCarSize").val();
				if(0 == shopCarSize) {
					jAlert("请先选购商品！");
					return false;
				} else {
					location.href='${base}/orderFrontCtl/persionShopCar';
				}
			}
			
			function confirmDate() {
				var remark = $("#remark").val();
				var startDateStr = $("#startDate").val();
				var endDateStr = $("#endDate").val();
				if("" == startDateStr || "" == endDateStr) {
					jAlert("选择起始和结束时间!");
					return ;
				}
				var startDate = new Date(startDateStr);
				var endDate = new Date(endDateStr);
				if(startDate > endDate) {
					jAlert("请检查订餐时间!");
					return ;
				}
				if("" != remark.trim()) {
 					if(!new RegExp(regexEnum.Illegal).test(remark)) {
	 					jAlert("备注中包含非法字符！");
	 					return;
 					}
				}
				//本周订餐天数
				var nowWeekDateCount = 6 - startDate.getDay();
				//总订餐天数
				var orderDayCount = 0;
				//结束时间和起始时间之间的天数
				var dayCount = (endDate.getTime() - startDate.getTime())/(3600*24*1000) + 1;
				//超出本周的天数
				if(dayCount > nowWeekDateCount) {
					orderDayCount += nowWeekDateCount;
					//中间有多少周(每周按5天算)
					var weekCount = Math.floor((dayCount - nowWeekDateCount) / 7);
					orderDayCount += weekCount * 5;
					//剩余的天数(减去周末2天)
					var weekDay = (dayCount - nowWeekDateCount) % 7;
					if(2 <= weekDay) {
						orderDayCount += weekDay - 2;
					}
				} else {
					orderDayCount = dayCount;
				}
				var waresId = parseInt($("#waresId").val());
				var waresPrice = parseInt($("#waresPrice").val());
				var waresType = parseInt($("#waresType").val());
				var orderType = parseInt($("#orderType").val());
				//套餐订购天数超过5天
				if(2 == waresType) {
					if(5 <= orderDayCount) {
						waresPrice -= 3;
					}
				}
				var orderTotalPrice = waresPrice * orderDayCount;
				
				$.ajax({
					url : "${base}/orderFrontCtl/addPersionShopCar",
					type : "post",
					data:{
						startDate : startDateStr,
						endDate : endDateStr,
						orderType : orderType,
						waresId : waresId,
						waresType : waresType,
						orderDayCount : orderDayCount,
						remark : remark
					},
					success: function (result) {
						if(true == result) {
							jAlert("您共预定了" + orderDayCount + "天的套餐，共计￥" + orderTotalPrice + "元！");
							$("#totalPrice").html("￥" + orderTotalPrice + "元");
							$("#subBtn").hide();
							$("#shopCarSize").val(orderDayCount);
						}
					}
				});
			}
		</script>
	</head>
	
	<body>
		<div class="main">
			<%@ include file="/common/header.jsp" %>
		    <div class="delivery">
		        <div class="map">
		        	<h1>Select&nbsp;your&nbsp;area&nbsp;&nbsp;选择区域</h1>
		            <p>
		            	目前我们已开通的送货区域自双井往国贸三环内、外3公里内，自国贸至三元桥、建国门至东直门二环至三环区间，三环外3公里内。如果您所需要送货地点位于此
						区域外，我们暂时不能提供免费配送。若有需要请联系XXX
					</p>
					<div class="map_img"><img src="${base}/images/map_01.jpg" alt="" /></div>
		        	<img src="${base}/images/mapbg_03.jpg" alt="" />
		        </div>
		        <div class="delivery_title">
		        	<h1>个人及配送信息</h1>
		            <h2><img src="${base}/images/img_40.gif" alt="" />送餐日期</h2>
		        </div>
		        <div class="songcan">
		        	<input type="hidden" id="waresPrice" value="${waresPrice}" />
		        	<input type="hidden" id="orderType" value="${orderType}" />
		        	<input type="hidden" id="waresType" value="${waresType}" />
		        	<input type="hidden" id="waresId" value="${waresId}" />
		        	<input type="hidden" id="shopCarSize" value="${fn:length(persionShopCar.waresList)}" />
		        	<ul class="clearfix">
		            	<li>配送日期：</li>
		                <li>
		                	<input id="startDate" type="text" class="Wdate" style="width:190px; height:23px; margin:0 5px;cursor:pointer;" onfocus="WdatePicker({isShowClear:false,readOnly:true,disabledDays:[6,0],minDate:'%y-%M-%d'})" />至
		                	<input id="endDate" type="text" class="Wdate" style="width:190px; height:23px; margin:0 5px;cursor:pointer;" onfocus="WdatePicker({isShowClear:false,readOnly:true,disabledDays:[6,0],minDate:'%y-%M-%d'})" />
	                	</li>
		                <li>订餐金额：<span id="totalPrice">￥0元</span></li>
		            </ul>
		        </div>
		        <div class="delivery_title">
		            <h2><img src="${base}/images/img_40.gif" alt="" />备注</h2>
		        </div>
		        <div class="songcan">
		        	<ul class="clearfix">
		            	<li>食品备注：</li>
		                <li><input id="remark" type="text" class="day_02" maxlength="100" /></li>
		                <li><input id="subBtn" type="button" class="day_btn" value="加入餐盘" onclick="confirmDate()" /></li>
		            </ul>
		        </div>
		        <h3>
		        	<input type="button" class="day_jxdc" value="继续订餐" onclick="location.href='${base}/index'" />
		        	<input type="button" class="day_qfk" value="去付款" onclick="toPersionOrderInfo()"/>
	        	</h3> 
		    </div>
		    <%@ include file="/common/footer.jsp" %>
		</div>
	</body>
</html>